import configparser


def read_ini_config():
    config = configparser.ConfigParser()
    config.read('config.ini')

    default_section = config['DEFAULT']
    debug = default_section.getboolean('debug')
    port = default_section.getint('port')
    host = default_section.get('host')

    ocr_section = config['OCR']
    use_gpu = ocr_section.getboolean('use_gpu')
    # 控制是否启用文字方向分类器
    use_angle_cls = ocr_section.getboolean('use_angle_cls')
    lang = ocr_section.get('lang')

    ocr_path_section = config['OCR_PATH']
    module = ocr_path_section.get('module')
    font = ocr_path_section.get('font')
    path = ocr_path_section.get('path')
    return {
        'debug': debug,
        'port': port,
        'host': host,
        'ocr': {
            'use_gpu': use_gpu,
            'use_angle_cls': use_angle_cls,
            'lang': lang
        },
        'ocr_path': {
            'module': module,
            'font': font,
            'path': path
        }
    }


configs = read_ini_config()
